package com.ldd.malphite.controller;

import com.ldd.malphite.dto.DepartmentDto;
import com.ldd.malphite.entity.Department;
import com.ldd.malphite.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentMapper departmentMapper;

    @GetMapping("getAll")
    public List<Department> getAll(){
        return departmentMapper.getAll();
    }

    @GetMapping("/getCascade")
    public DepartmentDto getCascade(){
        return departmentMapper.getCascade();
    }
    @GetMapping("/getCascadeBySql")
    public DepartmentDto getCascadeBySql(){
        return departmentMapper.getCascadeBySql();
    }

    @GetMapping("/insert")
    public void insert(){

        List<Department> departments = new ArrayList<>();
        Department department = new Department(1,"政府",0);
        Department department1 = new Department(2,"国务院",1);
        Department department1_1 = new Department(21,"一处",2);
        Department department1_2 = new Department(22,"二处",2);
        Department department1_3 = new Department(23,"三处",2);
        Department department1_4 = new Department(24,"四处",2);
        Department department1_5 = new Department(25,"五处",2);

        Department department2 = new Department(3,"公安部",1);
        Department department2_1 = new Department(31,"一处",3);
        Department department2_2 = new Department(32,"二处",3);
        Department department2_3 = new Department(33,"三处",3);
        Department department2_4 = new Department(34,"四处",3);
        Department department2_5 = new Department(35,"五处",3);

        Department department3 = new Department(4,"外交部",1);
        Department department3_1 = new Department(41,"一处",4);
        Department department3_2 = new Department(42,"二处",4);
        Department department3_3 = new Department(43,"三处",4);
        Department department3_4 = new Department(44,"四处",4);
        Department department3_5 = new Department(45,"五处",4);

        Department department4 = new Department(5,"环境部",1);
        Department department4_1 = new Department(51,"一处",5);
        Department department4_2 = new Department(52,"二处",5);
        Department department4_3 = new Department(53,"三处",5);
        Department department4_4 = new Department(54,"四处",5);
        Department department4_5 = new Department(55,"五处",5);

        Department department5 = new Department(6,"安全部",1);
        Department department5_1 = new Department(61,"一处",6);
        Department department5_2 = new Department(62,"二处",6);
        Department department5_3 = new Department(63,"三处",6);
        Department department5_4 = new Department(64,"四处",6);
        Department department5_5 = new Department(65,"五处",6);

        Department department6 = new Department(7,"国防部",1);
        Department department6_1 = new Department(71,"一处",7);
        Department department6_2 = new Department(72,"二处",7);
        Department department6_3 = new Department(73,"三处",7);
        Department department6_4 = new Department(74,"四处",7);
        Department department6_5 = new Department(75,"五处",7);

        Department department7 = new Department(8,"财政部",1);
        Department department7_1 = new Department(81,"一处",8);
        Department department7_2 = new Department(82,"二处",8);
        Department department7_3 = new Department(83,"三处",8);
        Department department7_4 = new Department(84,"四处",8);
        Department department7_5 = new Department(85,"五处",8);

        Department department8 = new Department(9,"商务部",1);
        Department department8_1 = new Department(91,"一处",9);
        Department department8_2 = new Department(92,"二处",9);
        Department department8_3 = new Department(93,"三处",9);
        Department department8_4 = new Department(94,"四处",9);
        Department department8_5 = new Department(95,"五处",9);

        Department department9 = new Department(10,"民政部",1);
        Department department9_1 = new Department(101,"一处",10);
        Department department9_2 = new Department(102,"二处",10);
        Department department9_3 = new Department(103,"三处",10);
        Department department9_4 = new Department(104,"四处",10);
        Department department9_5 = new Department(105,"五处",10);

        departments.add(department);
        departments.add(department1);
        departments.add(department1_1);
        departments.add(department1_2);
        departments.add(department1_3);
        departments.add(department1_4);
        departments.add(department1_5);
        departments.add(department2);
        departments.add(department2_1);
        departments.add(department2_2);
        departments.add(department2_3);
        departments.add(department2_4);
        departments.add(department2_5);
        departments.add(department3);
        departments.add(department3_1);
        departments.add(department3_2);
        departments.add(department3_3);
        departments.add(department3_4);
        departments.add(department3_5);
        departments.add(department4);
        departments.add(department4_1);
        departments.add(department4_2);
        departments.add(department4_3);
        departments.add(department4_4);
        departments.add(department4_5);
        departments.add(department5);
        departments.add(department5_1);
        departments.add(department5_2);
        departments.add(department5_3);
        departments.add(department5_4);
        departments.add(department5_5);
        departments.add(department6);
        departments.add(department6_1);
        departments.add(department6_2);
        departments.add(department6_3);
        departments.add(department6_4);
        departments.add(department6_5);
        departments.add(department7);
        departments.add(department7_1);
        departments.add(department7_2);
        departments.add(department7_3);
        departments.add(department7_4);
        departments.add(department7_5);
        departments.add(department8);
        departments.add(department8_1);
        departments.add(department8_2);
        departments.add(department8_3);
        departments.add(department8_4);
        departments.add(department8_5);
        departments.add(department9);
        departments.add(department9_1);
        departments.add(department9_2);
        departments.add(department9_3);
        departments.add(department9_4);
        departments.add(department9_5);
        departmentMapper.insert(departments);
    }
}
